import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:oral_cloud/config/resource_mananger.dart';

enum ImageType {
  normal,
  assets, //资源目录
}

class WrapperImage extends StatelessWidget {
  final String url;
  final double width;
  final double height;
  final BoxFit fit;
  final ImageType imageType;
  final String placeholder;

  WrapperImage(
      {@required this.url, this.width, this.height,
      this.imageType: ImageType.normal,
      this.placeholder:'image_default.png',
      this.fit: BoxFit.contain});

  @override
  Widget build(BuildContext context) {
    return imageType==ImageType.normal?CachedNetworkImage(
      imageUrl: imageUrl,
      width: width,

      height: height,
      placeholder: (_, __) =>
          Image.asset(ImageHelper.wrapAssets(placeholder),width: width,height: height,),
      errorWidget: (_, __, ___) =>
          Image.asset(ImageHelper.wrapAssets(placeholder),width: width,height: height,),
      fit: fit,
    ):Image.asset(imageUrl);
  }

  String get imageUrl {
    switch (imageType) {
      case ImageType.assets:
        return ImageHelper.wrapAssets(url);
      case ImageType.normal:
        return url;
    }
    return url;
  }
}
